package day01;

import util.ListNode;

import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;

/**
 * @author wangxi created on 2022/11/6 23:05
 * @version v1.0
 */
public class Main {
//    public static void main(String[] args) {
//        Main main = new Main();
//    }

    public int findKthLargest(int[] nums, int k) {
        if (nums == null || nums.length <= 0) {
            return -1;
        }
        // 小到大排序
        PriorityQueue<Integer> minQueue = new PriorityQueue<>((o1, o2) -> {
           return o1 - o2;
        });
        for (int i = 0; i < nums.length; i++) {
            minQueue.offer(nums[i]);
            if (minQueue.size() > k) {
                minQueue.poll();
            }
        }
        return minQueue.peek();
    }
}
